package com.example.sxmall.service.impl;

import com.example.sxmall.dao.mapper.UserMapper;
import com.example.sxmall.dao.pojo.Users;
import com.example.sxmall.service.LoginService;
import com.example.sxmall.service.UserService;
import com.example.sxmall.vo.ErrorCode;
import com.example.sxmall.vo.Result;
import com.example.sxmall.vo.params.loginParams;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class LoginServiceImpl implements LoginService {
    @Autowired
    private UserMapper userMapper;
    @Autowired
    private UserService userService;

    @Override
    public Result login(loginParams loginParams) {
        String utel = loginParams.getUtel();
        String upwd = loginParams.getUpwd();
        if (StringUtils.isBlank(utel) || StringUtils.isBlank(upwd)) {
            return Result.buildError(ErrorCode.ACCOUNT_PWD_NOT_EXIST.getCode(), ErrorCode.ACCOUNT_PWD_NOT_EXIST.getMsg());
        }
        Users loginUser = userService.findUser(utel, upwd);
        if (loginUser != null) {
            return Result.buildSuccess(loginUser);
        } else {
            return Result.buildError(ErrorCode.ACCOUNT_PWD_ERROR.getCode(), ErrorCode.ACCOUNT_PWD_ERROR.getMsg());
        }
    }
}
